/*
Copyright (C) 2013-2021 LZE

union-find set
*/
#include<bits/stdc++.h>
#define INF 0x7f7f7f7f
using namespace std;
typedef long long ll;
const int N=10001;
int n,m,z,x,y,father[N];
int find(int value){
    if(value==father[value])return value;
    return father[value]=find(father[value]);
}
void union_(int x,int y){
    father[find(y)]=father[find(x)];
}
bool find(int x,int y){
    if(find(x)==find(y))return true;
    return false;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        father[i]=i;
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&z,&x,&y);
        switch(z){
            case 1:{
                union_(x,y);
                break;
            }
            case 2:{
                if(find(x,y))cout<<"Y"<<endl;
                else cout<<"N"<<endl;
                break;
            }
        }
    }
    return 0;
}